<?php
namespace Admin\Controller;

class CacheController extends \Common\Controller\BaseController{

	//后台清除缓存操作，暂时只有thinkphp框架下的模板缓存更新
	public function index(){
		if(IS_POST){
			$cache = $_POST['cache'];
			foreach($cache as $val){
				@unlink(RUNTIME_PATH.$val);
			}
			$this->success("缓存更新成功！");
		}else{
			$this->display();
		}
		$applist = F('apps','',$cache_dir);
		$apps = array_keys($applist);
		array_push($apps,'admin','usercore');   //加入后台管理以及api的缓存更新
		foreach($apps as $v){
			$this->delDirAndFile($cache_dir.$v);
		}
		
	}

	function delDirAndFile( $dirName ){
		if($handle = opendir("$dirName")){
			while(false !== ($item = readdir($handle))){
				if($item != "." && $item != ".."){
					if(is_dir("$dirName/$item")){
						$this->delDirAndFile("$dirName/$item");
					}else{
						@unlink("$dirName/$item");
					}
				}
			}
			closedir($handle);
			rmdir($dirName);
		}
	}

	//获取文件名后缀
	function fileext($filename) {
		return strtolower(trim(substr(strrchr($filename, '.'), 1)));
	}
}
?>